/**
 * 
 * @param {}
 *            tp
 * @param {}
 *            combolabel
 * @param {}
 *            returnIdField
 * @param {}
 *            returnNameField
 * @param {}
 *            allowBlank
 * @param {}
 *            formId
 * @return {}
 */
function getWBComboStore(tp, combolabel, returnIdField, returnNameField,
		allowBlank, formId) {
	var comboId = formId + '_' + returnIdField + '_';

	var id = returnIdField + 'id';
	var name = returnIdField + 'name';

	var store = new Ext.data.Store({
				proxy : new Ext.data.ScriptTagProxy({
							url : context + '/system/wb.do?method=store&type='
									+ tp
						}), // 数据源
				reader : new Ext.data.ArrayReader({}, [ // 如何解析
						{
									name : id
								}, {
									name : name
								}])

			});

	store.on('load', function() {
				if (Ext.getCmp(formId).getForm().findField(returnIdField)
						&& Ext.getCmp(formId).getForm()
								.findField(returnIdField).getValue() != '') {				
					Ext.getCmp(comboId).setValue(Ext.getCmp(formId).getForm()
							.findField(returnIdField).getValue());
				}
			});

	var combobox = new Ext.form.ComboBox({
				id : comboId,
				fieldLabel : combolabel,
				xtype : 'combo',
				selectOnFocus : true,
				emptyText : '请选择..',
				forceSelection : true,
				triggerAction : 'all',
				valueField : id, // 提交表单时，下拉框的值
				displayField : name, // 显示在页面上下拉框的值
				editable : false,
				allowBlank : (allowBlank == true),
				store : store,
				listeners : {
					select : function(combo, record, index) {
						// alert(record.data.id);
						// alert(record.data.name);
						/* 设置combo选择项真正对应的值 */
						var returnId = Ext.getCmp(formId).getForm()
								.findField(returnIdField);

						var returnName = Ext.getCmp(formId).getForm()
								.findField(returnNameField);

						if (returnId != null) {
							returnId.setValue(eval("record.data." + id));
						}
						if (returnName != null) {
							returnName.setValue(eval("record.data." + name));
						}

					}
				}
			});

	return combobox;
}

/**
 * 组选择树(多选)
 * 
 * @param {}
 *            combolabel
 * @param {}
 *            returnIdField
 * @param {}
 *            returnNameField
 * @param {}
 *            defaultValue
 * @param {}
 *            allowBlank
 * @return {}
 */
function getGroupSelectCombo(fieldLabel, returnIdField, returnNameField,
		returnTypeField, root, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var treeDivId = 'GroupSelectComboTree_' + formId + '_' + returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				editable : false,
				fieldLabel : fieldLabel,
				id : id,
				name : id,
				mode : 'local',
				triggerAction : 'all',
				maxHeight : 400,
				listWidth : 300,
				tpl : '<div id="' + treeDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	// 创建树形结构
	var tree = new Ext.tree.TreePanel({
		border : false,
		autoScroll : true,
		animate : false,
		height : 300,
		layout : 'fit',
		enableDD : false,
		containerScroll : false,
		rootVisible : false,
		loader : new Ext.tree.TreeLoader({
			dataUrl : context
					+ '/system/group/groupmapscript.jsp?type=NOROOT_GROUP_CHECK'
					+ ((root && root != '') ? '&id=' + root : '')
		}),
		listeners : {
			load : function(node) {
				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				var ids = Ext.getCmp(formId).getForm().findField(returnIdField)
						.getValue();
				var types = Ext.getCmp(formId).getForm()
						.findField(returnTypeField).getValue();

				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				if ((ids == node.attributes.realid)
						&& (types == node.attributes.type)) {
					node.select();
				}
			}
		},
		bbar : [{
			text : "选择",
			iconCls : 'icon-chk',
			handler : function() {
				var names = '', ids = '', types = '', selNodes = tree
						.getChecked();
				Ext.each(selNodes, function(node) {
							if (names.length > 0) {
								names += ',';
								ids += ',';
								types += ',';
							}
							names += node.text;
							ids += node.attributes.realid;
							types += node.attributes.type;
						});
				comboWithTooltip.setValue(names);
				if (Ext.getCmp(formId).getForm().findField(returnIdField)) {
					Ext.getCmp(formId).getForm().findField(returnIdField)
							.setValue(ids);

				}

				if (Ext.getCmp(formId).getForm().findField(returnNameField)) {
					Ext.getCmp(formId).getForm().findField(returnNameField)
							.setValue(names);
				}

				if (Ext.getCmp(formId).getForm().findField(returnTypeField)) {
					Ext.getCmp(formId).getForm().findField(returnTypeField)
							.setValue(types);
				}
				comboWithTooltip.collapse();
			}
		}]

	});

	var root = new Ext.tree.AsyncTreeNode({
				text : '组根节点', // 节点名称
				draggable : false, // 是否支持拖动
				id : '0' // 节点id
			});

	var temp = new Ext.tree.TreeNode({
				id : 'gtemp',
				realid : 'temp',
				type : 'group',
				iconCls : 'icon-grouptemp',
				text : '临时组',
				checked : false
			});

	tree.setRootNode(root);
	comboWithTooltip.on('expand', function() {
				tree.render(treeDivId);
				tree.expandAll();
			});

	return comboWithTooltip;

}

/**
 * 组和用户混合多选树(节点带有checkbox)
 * 
 * @param {}
 *            combolabel
 * @param {}
 *            returnIdField
 * @param {}
 *            returnNameField
 * @param {}
 *            returnTypeField
 * @param {}
 *            defaultValue
 * @param {}
 *            allowBlank
 * @return {}
 */
function getGroupUserChkCombo(fieldLabel, returnIdField, returnNameField,
		returnTypeField, root, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var treeDivId = 'getGroupUserChkComboTree_' + formId + '_' + returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				editable : false,
				id : id,
				name : id,
				fieldLabel : fieldLabel,
				mode : 'local',
				triggerAction : 'all',
				maxHeight : 400,
				listWidth : 300,
				tpl : '<div id="' + treeDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	// 创建树形结构
	var tree = new Ext.tree.TreePanel({
		border : false,
		autoScroll : true,
		animate : false,
		height : 300,
		layout : 'fit',
		enableDD : false,
		containerScroll : false,
		rootVisible : false,
		loader : new Ext.tree.TreeLoader({
			dataUrl : context
					+ '/system/group/groupmapscript.jsp?type=NOROOT_GROUPUSER_CHECKALL'
					+ ((root && root != '') ? '&id=' + root : '')
		}),
		listeners : {
			load : function(node) {
				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				var ids = Ext.getCmp(formId).getForm().findField(returnIdField)
						.getValue();
				var types = Ext.getCmp(formId).getForm()
						.findField(returnTypeField).getValue();

				for (var j = 0; j < node.childNodes.length; j++) {
					if (isCheckedGUNode(node.childNodes[j].attributes.realid,
							node.childNodes[j].attributes.type, ids, types)) {
						// node.childNodes[j].select();
						node.childNodes[j].attributes.checked = true;
					}
				}

			}
		},
		bbar : [{
			text : "选择",
			iconCls : 'icon-chk',
			handler : function() {
				var names = '', ids = '', types = '', selNodes = tree
						.getChecked();
				Ext.each(selNodes, function(node) {
							if (names.length > 0) {
								names += ',';
								ids += ',';
								types += ',';
							}
							names += node.text;
							ids += node.attributes.realid;
							types += node.attributes.type;
						});
				comboWithTooltip.setValue(names);
				if (Ext.getCmp(formId).getForm().findField(returnIdField)) {
					Ext.getCmp(formId).getForm().findField(returnIdField)
							.setValue(ids);

				}

				if (Ext.getCmp(formId).getForm().findField(returnNameField)) {
					Ext.getCmp(formId).getForm().findField(returnNameField)
							.setValue(names);
				}

				if (Ext.getCmp(formId).getForm().findField(returnTypeField)) {
					Ext.getCmp(formId).getForm().findField(returnTypeField)
							.setValue(types);
				}
				comboWithTooltip.collapse();
			}
		}]

	});

	var root = new Ext.tree.AsyncTreeNode({
				text : '组根节点', // 节点名称
				draggable : false, // 是否支持拖动
				id : '0' // 节点id
			});

	var temp = new Ext.tree.TreeNode({
				id : 'gtemp',
				realid : 'temp',
				type : 'group',
				iconCls : 'icon-grouptemp',
				text : '临时组',
				checked : false
			});

	tree.setRootNode(root);
	comboWithTooltip.on('expand', function() {
				tree.render(treeDivId);
				tree.expandAll();
			});

	return comboWithTooltip;
}

/**
 * 只选择用户机构树(多选)
 * 
 * @param {}
 *            returnIdField
 * @param {}
 *            returnNameField
 * @param {}
 *            returnTypeField
 * @param {}
 *            root
 * @param {}
 *            allowBlank
 * @return {}
 */
function getUserChkCombo(fieldLabel, returnIdField, returnNameField,
		returnTypeField, root, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var treeDivId = 'UserChkComboTree_' + formId + '_' + returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				editable : false,
				fieldLabel : fieldLabel,
				id : id,
				name : id,
				mode : 'local',
				triggerAction : 'all',
				maxHeight : 400,
				listWidth : 300,
				tpl : '<div id="' + treeDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	// 创建树形结构
	var tree = new Ext.tree.TreePanel({
		border : false,
		autoScroll : true,
		animate : false,
		height : 300,
		layout : 'fit',
		enableDD : false,
		containerScroll : false,
		rootVisible : false,
		loader : new Ext.tree.TreeLoader({
			dataUrl : context
					+ '/system/group/groupmapscript.jsp?type=NOROOT_GROUPUSER_CHECKUSER'
					+ ((root && root != '') ? '&id=' + root : '')
		}),
		listeners : {
			load : function(node) {
				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				var ids = Ext.getCmp(formId).getForm().findField(returnIdField)
						.getValue();
				var types = Ext.getCmp(formId).getForm()
						.findField(returnTypeField).getValue();

				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				if ((ids == node.attributes.realid)
						&& (types == node.attributes.type)) {
					node.select();
				}
			}
		},
		bbar : [{
			text : "选择",
			iconCls : 'icon-chk',
			handler : function() {
				var names = '', ids = '', types = '', selNodes = tree
						.getChecked();
				Ext.each(selNodes, function(node) {
							if (names.length > 0) {
								names += ',';
								ids += ',';
								types += ',';
							}
							names += node.text;
							ids += node.attributes.realid;
							types += node.attributes.type;
						});
				comboWithTooltip.setValue(names);
				if (Ext.getCmp(formId).getForm().findField(returnIdField)) {
					Ext.getCmp(formId).getForm().findField(returnIdField)
							.setValue(ids);

				}

				if (Ext.getCmp(formId).getForm().findField(returnNameField)) {
					Ext.getCmp(formId).getForm().findField(returnNameField)
							.setValue(names);
				}

				if (Ext.getCmp(formId).getForm().findField(returnTypeField)) {
					Ext.getCmp(formId).getForm().findField(returnTypeField)
							.setValue(types);
				}
				comboWithTooltip.collapse();
			}
		}]

	});

	var root = new Ext.tree.AsyncTreeNode({
				text : '组根节点', // 节点名称
				draggable : false, // 是否支持拖动
				id : '0' // 节点id
			});

	var temp = new Ext.tree.TreeNode({
				id : 'gtemp',
				realid : 'temp',
				type : 'group',
				iconCls : 'icon-grouptemp',
				text : '临时组',
				checked : false
			});

	tree.setRootNode(root);
	comboWithTooltip.on('expand', function() {
				tree.render(treeDivId);
				tree.expandAll();
			});

	return comboWithTooltip;
}

/**
 * 组选择树(单选)
 * 
 * @param {}
 *            combolabel
 * @param {}
 *            returnIdField
 * @param {}
 *            returnNameField
 * @param {}
 *            defaultValue
 * @param {}
 *            allowBlank
 * @return {}
 */
function getGroupSelectCombo4Single(fieldLabel, returnIdField, returnNameField,
		returnTypeField, root, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var treeDivId = 'GroupSelectCombo4SingleTree_' + formId + '_'
			+ returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				editable : false,
				fieldLabel : fieldLabel,
				id : id,
				name : id,
				mode : 'local',
				triggerAction : 'all',
				maxHeight : 400,
				listWidth : 300,
				tpl : '<div id="' + treeDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	// 创建树形结构
	var tree = new Ext.tree.TreePanel({
		border : false,
		autoScroll : true,
		animate : false,
		height : 300,
		layout : 'fit',
		enableDD : false,
		containerScroll : false,
		rootVisible : false,
		loader : new Ext.tree.TreeLoader({
					dataUrl : context
							+ '/system/group/groupmapscript.jsp?type=NOROOT_GROUP'
							+ ((root && root != '') ? '&id=' + root : '')
				}),
		listeners : {
			load : function(node) {
				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				var ids = Ext.getCmp(formId).getForm().findField(returnIdField)
						.getValue();
				var types = Ext.getCmp(formId).getForm()
						.findField(returnTypeField).getValue();

				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				if ((ids == node.attributes.realid)
						&& (types == node.attributes.type)) {
					node.select();
				}
			}
		}

	});

	tree.on("click", function(node, event) {
				comboWithTooltip.setValue(node.text);
				if (Ext.getCmp(formId).getForm().findField(returnIdField)) {
					Ext.getCmp(formId).getForm().findField(returnIdField)
							.setValue(node.attributes.realid);

				}

				if (Ext.getCmp(formId).getForm().findField(returnNameField)) {
					Ext.getCmp(formId).getForm().findField(returnNameField)
							.setValue(node.text);
				}

				if (Ext.getCmp(formId).getForm().findField(returnTypeField)) {
					Ext.getCmp(formId).getForm().findField(returnTypeField)
							.setValue(node.attributes.type);
				}

				comboWithTooltip.collapse();
			});

	var root = new Ext.tree.AsyncTreeNode({
				text : '组根节点', // 节点名称
				draggable : false, // 是否支持拖动
				id : '0' // 节点id
			});

	var temp = new Ext.tree.TreeNode({
				id : 'gtemp',
				realid : 'temp',
				type : 'group',
				iconCls : 'icon-grouptemp',
				text : '临时组',
				checked : false
			});

	tree.setRootNode(root);
	comboWithTooltip.on('expand', function() {
				tree.render(treeDivId);
				tree.expandAll();
			});

	return comboWithTooltip;
}

/**
 * 组和用户混合多选树(单选)
 * 
 * @param {}
 *            combolabel
 * @param {}
 *            returnIdField
 * @param {}
 *            returnNameField
 * @param {}
 *            returnTypeField
 * @param {}
 *            defaultValue
 * @param {}
 *            allowBlank
 * @return {}
 */
function getGroupUserChkCombo4Single(fieldLabel, returnIdField,
		returnNameField, returnTypeField, root, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var treeDivId = 'GroupUserChkComboTree_' + formId + '_' + returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				editable : false,
				fieldLabel : fieldLabel,
				id : id,
				name : id,
				mode : 'local',
				triggerAction : 'all',
				maxHeight : 400,
				listWidth : 300,
				tpl : '<div id="' + treeDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	// 创建树形结构
	var tree = new Ext.tree.TreePanel({
		border : false,
		autoScroll : true,
		animate : false,
		height : 300,
		layout : 'fit',
		enableDD : false,
		containerScroll : false,
		rootVisible : false,
		loader : new Ext.tree.TreeLoader({
					dataUrl : context
							+ '/system/group/groupmapscript.jsp?type=NOROOT_GROUPUSER'
							+ ((root && root != '') ? '&id=' + root : '')
				}),
		listeners : {
			load : function(node) {
				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				var ids = Ext.getCmp(formId).getForm().findField(returnIdField)
						.getValue();
				var types = Ext.getCmp(formId).getForm()
						.findField(returnTypeField).getValue();

				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				if ((ids == node.attributes.realid)
						&& (types == node.attributes.type)) {
					node.select();
				}
			}
		}

	});

	tree.on("click", function(node, event) {
				comboWithTooltip.setValue(node.text);
				if (Ext.getCmp(formId).getForm().findField(returnIdField)) {
					Ext.getCmp(formId).getForm().findField(returnIdField)
							.setValue(node.attributes.realid);

				}

				if (Ext.getCmp(formId).getForm().findField(returnNameField)) {
					Ext.getCmp(formId).getForm().findField(returnNameField)
							.setValue(node.text);
				}

				if (Ext.getCmp(formId).getForm().findField(returnTypeField)) {
					Ext.getCmp(formId).getForm().findField(returnTypeField)
							.setValue(node.attributes.type);
				}

				comboWithTooltip.collapse();
			});

	var root = new Ext.tree.AsyncTreeNode({
				text : '组根节点', // 节点名称
				draggable : false, // 是否支持拖动
				id : '0' // 节点id
			});

	var temp = new Ext.tree.TreeNode({
				id : 'gtemp',
				realid : 'temp',
				type : 'group',
				iconCls : 'icon-grouptemp',
				text : '临时组',
				checked : false
			});

	tree.setRootNode(root);
	comboWithTooltip.on('expand', function() {
				tree.render(treeDivId);
				tree.expandAll();
			});

	return comboWithTooltip;
}

/**
 * 用户选择树(单选)
 * 
 * @param {}
 *            returnIdField
 * @param {}
 *            returnNameField
 * @param {}
 *            returnTypeField
 * @param {}
 *            root
 * @param {}
 *            allowBlank
 * @return {}
 */
function getUserChkCombo4Single(fieldLabel, returnIdField, returnNameField,
		returnTypeField, root, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var treeDivId = 'UserChkCombo4SingleTree_' + formId + '_' + returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				editable : false,
				fieldLabel : fieldLabel,
				id : id,
				name : id,
				mode : 'local',
				triggerAction : 'all',
				maxHeight : 400,
				listWidth : 300,
				tpl : '<div id="' + treeDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	// 创建树形结构
	var tree = new Ext.tree.TreePanel({
		border : false,
		autoScroll : true,
		animate : false,
		height : 300,
		layout : 'fit',
		enableDD : false,
		containerScroll : false,
		rootVisible : false,
		loader : new Ext.tree.TreeLoader({
					dataUrl : context
							+ '/system/group/groupmapscript.jsp?type=NOROOT_GROUPUSER'
							+ ((root && root != '') ? '&id=' + root : '')
				}),
		listeners : {
			load : function(node) {
				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				var ids = Ext.getCmp(formId).getForm().findField(returnIdField)
						.getValue();
				var types = Ext.getCmp(formId).getForm()
						.findField(returnTypeField).getValue();

				if (node.id == '0') {
					/* 手工添加临时组节点 */
					// node.appendChild(temp);
				}

				if ((ids == node.attributes.realid)
						&& (types == node.attributes.type)) {
					node.select();
				}
			}
		}

	});

	tree.on("click", function(node, event) {
				if (node.attributes.type == 'group') {
					alert('请选择用户');
				} else {
					comboWithTooltip.setValue(node.text);
					if (Ext.getCmp(formId).getForm().findField(returnIdField)) {
						Ext.getCmp(formId).getForm().findField(returnIdField)
								.setValue(node.attributes.realid);

					}

					if (Ext.getCmp(formId).getForm().findField(returnNameField)) {
						Ext.getCmp(formId).getForm().findField(returnNameField)
								.setValue(node.text);
					}

					if (Ext.getCmp(formId).getForm().findField(returnTypeField)) {
						Ext.getCmp(formId).getForm().findField(returnTypeField)
								.setValue(node.attributes.type);
					}

					comboWithTooltip.collapse();
				}
			});

	var root = new Ext.tree.AsyncTreeNode({
				text : '组根节点', // 节点名称
				draggable : false, // 是否支持拖动
				id : '0' // 节点id
			});

	var temp = new Ext.tree.TreeNode({
				id : 'gtemp',
				realid : 'temp',
				type : 'group',
				iconCls : 'icon-grouptemp',
				text : '临时组',
				checked : false
			});

	tree.setRootNode(root);
	comboWithTooltip.on('expand', function() {
				tree.render(treeDivId);
				tree.expandAll();
			});

	return comboWithTooltip;
}

/**
 * 数据类别
 * 
 * @param {}
 *            returnIdField
 * @param {}
 *            returnNameField
 * @param {}
 *            root
 * @param {}
 *            allowBlank
 * @return {}
 */
function getDataIndexCombo(fieldLabel, returnIdField, returnNameField,
		returnTypeField, root, allowBlank, returnFunc, formId) {
	var id = formId + '_' + returnIdField + '_';
	var treeDivId = 'DataindexComboTree_' + formId + '_' + returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				editable : false,
				id : id,
				name : id,
				fieldLabel : fieldLabel,
				mode : 'local',
				triggerAction : 'all',
				maxHeight : 400,
				listWidth : 300,
				tpl : '<div id="' + treeDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	// 创建树形结构
	var tree = new Ext.tree.TreePanel({
				border : false,
				autoScroll : true,
				animate : true,
				height : 200,
				layout : 'fit',
				enableDD : false,
				containerScroll : false,
				rootVisible : false,
				loader : new Ext.tree.TreeLoader({
							dataUrl : context
									+ '/system/ddindexshow.do?method=alltree'
									+ ((root && root != '')
											? '&key=' + root
											: '')
						}),
				listeners : {
					load : function(node) {
						var ids = Ext.getCmp(formId).getForm()
								.findField(returnIdField).getValue();

						if (node.id == '0') {
							/* 手工添加临时组节点 */
							// node.appendChild(temp);
						}

						for (var j = 0; j < node.childNodes.length; j++) {
							if (ids == node.childNodes[j].id) {
								// node.childNodes[j].select();
							}
						}
					}
				}
			});

	tree.on('click', function(node, event) {
				comboWithTooltip.setValue(node.text);
				if (Ext.getCmp(formId).getForm().findField(returnIdField)) {
					Ext.getCmp(formId).getForm().findField(returnIdField)
							.setValue(node.id);

				}

				if (Ext.getCmp(formId).getForm().findField(returnNameField)) {
					Ext.getCmp(formId).getForm().findField(returnNameField)
							.setValue(node.text);
				}

				if (returnTypeField != null
						&& Ext.getCmp(formId).getForm()
								.findField(returnTypeField)) {
					Ext.getCmp(formId).getForm().findField(returnTypeField)
							.setValue(node.attributes.code);
				}

				comboWithTooltip.collapse();

				if (returnFunc != null) {
					returnFunc(node);
				}
			});

	var root = new Ext.tree.AsyncTreeNode({
				text : '数据类别根节点', // 节点名称
				draggable : false, // 是否支持拖动
				id : '0' // 节点id
			});

	tree.setRootNode(root);
	comboWithTooltip.on('expand', function() {
				tree.render(treeDivId);
				tree.expandAll();
			});

	return comboWithTooltip;
}

/**
 * 是否默认选中
 * 
 * @param {}
 *            id
 * @param {}
 *            ids
 * @return {}
 */
function isCheckedDataIndexNode(id, ids) {
	var idstr = ids.split(",");
	var rnt = false;

	for (var i = 0; i < idstr.length; i++) {
		if (id == idstr[i]) {

			rnt = true;
			break;
		}
	}

	return rnt;
}

function isCheckedGUNode(id, type, ids, types) {
	var idstr = ids.split(",");
	var typestr = types.split(",");
	var rnt = false;
	if (idstr.length == typestr.length) {
		for (var i = 0; i < idstr.length; i++) {
			if (type == typestr[i] && id == idstr[i]) {

				rnt = true;
				break;
			}
		}
	}

	return rnt;
}

function hasSelectTQGridRecord(ids, recordId) {
	var r = false;
	var idstr = ids.split(',');
	for (var i = 0; i < idstr.length; i++) {
		if (idstr[i] == recordId) {
			r = true;
			break;
		}
	}
	return r;
}

/**
 * 初始化对象数据信息在form组件中
 * 
 * @param {}
 *            key 查询key
 * @param {}
 *            func 查询成功后回调函数(开发者自定义)
 * @param {}
 *            returnIdField 接收返回值(ID)的表单ID
 * @param {}
 *            returnIdField 接收返回值(NAME)的表单ID
 * @param {}
 *            pointToId 返回id
 * @param {}
 *            pointToName 返回value
 * @param {}
 *            allowBlank 非必选项
 */
function getTableQueryCombo(fieldLabel, key, func, setFunc, returnIdField,
		returnNameField, pointId, pointName, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var treeDivId = 'TableQueryComboTree_' + formId + '_' + returnIdField;

	var borderPanel = initTVqueryList({
				tabid : formId + '_TQ_' + returnIdField,
				comboWithTooltip : id,
				pointId : pointId,
				pointName : pointName,
				setFunc : setFunc,
				formId : formId,
				returnIdField : returnIdField,
				returnNameField : returnNameField,
				querykey : key,
				func : func,
				pageSize : 20,
				height : 150
			});
			
	borderPanel.height = 400;	
	borderPanel.border = false;
			
	var grid = Ext.getCmp(formId + '_TQ_' + returnIdField + '_grid');		

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				editable : false,
				id : id,
				name : id,
				fieldLabel : fieldLabel,
				mode : 'local',
				triggerAction : 'all',
				listWidth : 600,
				maxHeight : 400,
				tpl : '<div id="' + treeDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : allowBlank,
				emptyText : '请选择...'
			});

	grid.on('render', function() {
				var total = grid.getStore().getCount();// 数据行数

				var arr = [];
				for (var j = 0; j < total; j++) {
					var record = grid.getStore().getAt(j);

					if (hasSelectTQGridRecord(Ext.getCmp(formId).getForm()
									.findField(returnIdField).getValue(),
							record.get(pointId))) {
						arr.push(record);
					}
				}
				grid.getSelectionModel().selectRecords(arr);
			}, this, {
				delay : 1000
			});

	comboWithTooltip.on('expand', function() {
				borderPanel.render(treeDivId);
				grid.getStore().load({
							params : {
								start : 0,
								limit : 20
							},
							callback : function(r, options, success) {
								if (success == false) {
									Ext.Msg.alert('ERROR', '加载数据出现异常.');
								} else {
									if (func) {
										func(querykey);
									}
								}
							}
						});
			});

	return comboWithTooltip;
}

/**
 * 获得角色列表combo(单选)
 * 
 * @return {}
 */
function getRoleSingleSelectCombo(combolabel, returnIdField, returnNameField,
		returnTypeField, defaultValue, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var listDivId = 'RoleSingleSelectCombo_' + formId + '_' + returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				fieldLabel : combolabel,
				editable : false,
				id : id,
				name : id,
				mode : 'local',
				triggerAction : 'all',
				listWidth : 450,
				maxHeight : 400,
				tpl : '<div id="' + listDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	var RoleListStore = new Ext.data.JsonStore({
				idProperty : 'id',
				remoteSort : false,
				totalProperty : 'totalCount',
				root : 'roleList',
				fields : ['id', 'name', 'memo', 'key', 'raccede', 'rv',
						'rvrating', 'rvtype'],

				// load using script tags for cross domain, if the data in on
				// the same domain as
				// this page, an HttpProxy would be better
				proxy : new Ext.data.ScriptTagProxy({
							url : context
									+ '/system/rolelist.do?method=selectlist'
						})
			});

	var sm = new Ext.grid.CheckboxSelectionModel({
				singleSelect : true,
				handleMouseDown : Ext.emptyFn
			});

	var RoleListGrid = new Ext.grid.GridPanel({
				store : RoleListStore,
				columns : [sm, {
							header : '角色名称',
							width : 150,
							sortable : true,
							dataIndex : 'name'
						}, {
							header : '角色说明',
							width : 150,
							sortable : true,
							dataIndex : 'memo'
						}],
				sm : sm,
				stripeRows : true,
				autoExpandColumn : 'name',
				layout : 'fit',
				height : 250,
				border : false,
				viewConfig : {
					forceFit : true
				},
				// config options for stateful behavior
				stateful : true,
				stateId : 'grid',
				loadMask : {
					msg : "数据加载中，请稍等..."
				},
				bbar : [{
					text : "选 择",
					iconCls : 'icon-pselectuser',
					handler : function() {
						var names = '', ids = '', types = '', selNodes = RoleListGrid
								.getSelectionModel().getSelections();
						Ext.each(selNodes, function(node) {
									if (names.length > 0) {
										names += ',';
										ids += ',';
										types += ',';
									}
									names += node.data.name;
									ids += node.data.id;
									types += node.data.key;
								});

						comboWithTooltip.setValue(names);
						if (Ext.getCmp(formId).getForm()
								.findField(returnIdField)) {
							Ext.getCmp(formId).getForm()
									.findField(returnIdField).setValue(ids);

						}

						if (Ext.getCmp(formId).getForm()
								.findField(returnNameField)) {
							Ext.getCmp(formId).getForm()
									.findField(returnNameField).setValue(names);
						}

						if (Ext.getCmp(formId).getForm()
								.findField(returnTypeField)) {
							Ext.getCmp(formId).getForm()
									.findField(returnTypeField).setValue(types);
						}
						comboWithTooltip.collapse();
					}
				}, {
					text : "取 消",
					iconCls : 'icon-punchk',
					handler : function() {
						comboWithTooltip.collapse();
					}
				}]
			});

	comboWithTooltip.on('expand', function() {
		RoleListGrid.render(listDivId);
		RoleListStore.load({
			params : {
				start : 0,
				limit : 20
			},
			callback : function(r, options, success) {
				if (success == false) {
					Ext.Msg.alert('ERROR', '加载数据出现异常.');
				} else {
					var total = RoleListGrid.getStore().getCount();// 数据行数

					var arr = [];
					for (var j = 0; j < total; j++) {
						var record = RoleListGrid.getStore().getAt(j);
						if (Ext.getCmp(formId).getForm()
								.findField(returnIdField).getValue() == record.data.id) {
							arr.push(record);
						}
					}
					if (arr.length > 0) {
						RoleListGrid.getSelectionModel().selectRecords(arr);
					}
				}
			}

		});
	});

	if (defaultValue) {
		comboWithTooltip.setValue(defaultValue);
	}

	return comboWithTooltip;
}

/**
 * 获得角色列表combo(多选)
 * 
 * @return {}
 */
function getRoleSelectCombo(combolabel, returnIdField, returnNameField,
		returnTypeField, defaultValue, allowBlank, formId) {
	var id = formId + '_' + returnIdField + '_';
	var listDivId = 'RoleSelect_' + formId + '_' + returnIdField;

	var comboWithTooltip = new Ext.form.ComboBox({
				store : new Ext.data.SimpleStore({
							fields : [],
							data : [[]]
						}),
				fieldLabel : combolabel,
				editable : false,
				id : id,
				name : id,
				mode : 'local',
				triggerAction : 'all',
				listWidth : 450,
				maxHeight : 400,
				tpl : '<div id="' + listDivId + '"></div>',
				selectedClass : '',
				onSelect : Ext.emptyFn,
				allowBlank : (allowBlank == true),
				emptyText : '请选择...'
			});

	var RoleListStore = new Ext.data.JsonStore({
				idProperty : 'id',
				remoteSort : false,
				totalProperty : 'totalCount',
				root : 'roleList',
				fields : ['id', 'name', 'memo', 'key', 'raccede', 'rv',
						'rvrating', 'rvtype'],

				// load using script tags for cross domain, if the data in on
				// the same domain as
				// this page, an HttpProxy would be better
				proxy : new Ext.data.ScriptTagProxy({
							url : context
									+ '/system/rolelist.do?method=selectlist'
						})
			});

	var sm = new Ext.grid.CheckboxSelectionModel();

	var RoleListGrid = new Ext.grid.GridPanel({
				store : RoleListStore,
				columns : [sm, {
							header : '角色名称',
							width : 150,
							sortable : true,
							dataIndex : 'name'
						}, {
							header : '角色说明',
							width : 150,
							sortable : true,
							dataIndex : 'memo'
						}],
				sm : sm,
				stripeRows : true,
				autoExpandColumn : 'name',
				region : 'center',
				layout : 'fit',
				height : 250,
				border : false,
				viewConfig : {
					forceFit : true
				},
				// config options for stateful behavior
				stateful : true,
				stateId : 'grid',
				loadMask : {
					msg : "数据加载中，请稍等..."
				},
				bbar : [{
					text : "选 择",
					iconCls : 'icon-pselectuser',
					handler : function() {
						var names = '', ids = '', types = '', selNodes = RoleListGrid
								.getSelectionModel().getSelections();
						Ext.each(selNodes, function(node) {
									if (names.length > 0) {
										names += ',';
										ids += ',';
										types += ',';
									}
									names += node.data.name;
									ids += node.data.id;
									types += node.data.key;
								});

						comboWithTooltip.setValue(names);
						if (Ext.getCmp(formId).getForm()
								.findField(returnIdField)) {
							Ext.getCmp(formId).getForm()
									.findField(returnIdField).setValue(ids);

						}

						if (Ext.getCmp(formId).getForm()
								.findField(returnNameField)) {
							Ext.getCmp(formId).getForm()
									.findField(returnNameField).setValue(names);
						}

						if (Ext.getCmp(formId).getForm()
								.findField(returnTypeField)) {
							Ext.getCmp(formId).getForm()
									.findField(returnTypeField).setValue(types);
						}
						comboWithTooltip.collapse();
					}
				}, {
					text : "取 消",
					iconCls : 'icon-punchk',
					handler : function() {
						comboWithTooltip.collapse();
					}
				}]
			});

	comboWithTooltip.on('expand', function() {
				RoleListGrid.render(listDivId);
				RoleListStore.load({
							params : {
								start : 0,
								limit : 20
							},
							callback : function(r, options, success) {
								if (success == false) {
									Ext.Msg.alert('ERROR', '加载数据出现异常.');
								} else {
									var total = RoleListGrid.getStore()
											.getCount();// 数据行数

									var arr = [];
									for (var j = 0; j < total; j++) {
										var record = RoleListGrid.getStore()
												.getAt(j);
										if (hasSelected(
												Ext
														.getCmp(formId)
														.getForm()
														.findField(returnIdField)
														.getValue(),
												record.data.id)) {
											arr.push(record);
										}
									}
									if (arr.length > 0) {
										RoleListGrid.getSelectionModel()
												.selectRecords(arr);
									}
								}
							}
						});
			});

	return comboWithTooltip;
}